'use strict';

/**
 * @ngdoc function
 * @name magisterkaGuiApp.controller:MasterCtrl
 * @description
 * # MasterCtrl
 * Controller of the magisterkaGuiApp
 */
angular.module('magisterkaGuiApp')
    .controller('MasterCtrl', function ($scope, $log, $window, Facebook,$rootScope) {

        //mozliwe ze najpierw sprobuje zrobic calla a potem dopiero mnei zautentykuje

        $scope.user = {
            loggedIn: false,
            //isAdmin:true
        };

        $scope.login = function () {
            Facebook.login(handleLoginResponse);
        };

        $scope.getLoginStatus = function () {
            Facebook.getLoginStatus(handleLoginResponse);
        };

        $scope.logout = function () {
            Facebook.logout(function (response) {
                $log.info('logout response', response);
                $scope.user.loggedIn = false;
                $scope.$apply();
            });
        }


        function handleLoginResponse(response) {
            if (response.status === 'connected') {
                $log.info('Connected');
                $scope.user.loggedIn = true;
            } else {
                $log.info('Not connected');
            }
            $scope.$apply();
        }

        $scope.getLoginStatus();
    });
